<template>
  <div class="box">
    <!-- Logo -->
    <div class="top">
      <div class="logo">登录</div>
    </div>
    <!-- 登录框 -->

    <div class="loginView">
      <span class="login_span">请填写登录信息:</span>
      <van-form @submit="onSubmit">
        <van-field
          style="font-size: 16px"
          v-model="phone"
          name="手机号"
          label="手机号"
          placeholder="手机号"
        />
        <van-field
          style="font-size: 16px"
          v-model="password"
          type="password"
          name="密码"
          label="密码"
          placeholder="密码"
        />
        <div style="margin: 16px">
          <van-button round block type="primary" color="#1074ff"
            >提交</van-button
          >
        </div>
      </van-form>
    </div>
    <!-- 其他登录方式 -->
    <div class="divider">
      <van-divider
        :style="{ color: '#01d99d', borderColor: '#1074ff', padding: '0 16px' }"
      >
        <router-link to="/register" style="color: #646566">注册</router-link>
      </van-divider>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      phone: "",
      password: "",
    };
  },
  methods: {
    onSubmit() {
      let params = `phone=${this.phone}&password=${this.password}`;
      this.axios
        .post(`${this.$base}user/login`, params)
        .then((res) => {
          // console.log(res, "111");
          if (res.data.code == 200) {
            this.$toast("登录成功");
            let id = res.data.data.id;
            // sessionStorage.setItem('uid', id)
            this.$store.commit("loginOK", id);
            this.$router.push("/home");
          } else {
            this.$toast.fail("密码错误");
          }
        });
    },
  },
};
</script>

<style scoped>
div /deep/ .van-field__label {
  width: 4em !important;
}
.login_span {
  display: block;
  /* color: #1074ff; */
  padding: 10px 16px;
}
.top {
  background: #1074ff linear-gradient(to top, rgba(0, 0, 0, 0), #5394ee);
  height: 40vh;
  display: flex;
  align-items: center;
}
.logo {
  font-size: 28px;
  line-height: 100px;
  text-align: center;
  width: 100px;
  height: 100px;
  background-color: white;
  color: #999999;
  margin: 0 auto;
  border-radius: 50%;
}
.box {
  width: 100vw;
  height: 100vh;
  background-color: #f8f8f8;
}
.loginView {
  background-color: white;
  padding-top: 10px;
  border-radius: 15px;
  width: 90vw;
  height: 40vh;
  margin: -5vh auto 0;
  box-shadow: 2px 2px 10px rgba(0, 0, 0, 0.2);
}
.divider {
  width: 100vw;
  position: absolute;
  bottom: 3vh;
}
</style>